﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenFile
{
    class Factory
    {
        /// <summary>
        /// 工厂模式
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static BaseFile GetFile(string filePath,string fileName)
        {
            BaseFile file = null;
            //获取文件名后辍，根据指定的后辍创建对应的对象
            string getExtension = Path.GetExtension(fileName);
            switch (getExtension)
            {
                case ".txt":
                    file = new TxtFile(filePath, fileName);
                    break;
                case ".gif":
                    file = new GIFFile(filePath, fileName);
                    break;
            }
            return file;
        }
    }
}
